﻿using Microsoft.WowAddonStudio.Lua.Loaders;

namespace Microsoft.WowAddonStudio.Lua.LanguageService.Intellisense.Providers
{
    public class HierarchyDeclarationProvider : DocumentationDeclarationProvider<TocDocumentationLoader<HierarchyStreamProvider>> 
    {
        private readonly IDocumentationDeclarationProvider parentDocumentationDeclarationProvider;

        /// <summary>
        /// Initializes a new instance of the <see cref="HierarchyDeclarationProvider"/> class.
        /// </summary>
        /// <param name="hierarchyStreamProvider">The hierarchy stream provider.</param>
        /// <param name="parentDocumentation">The parent documentation provider.</param>
        public HierarchyDeclarationProvider(HierarchyStreamProvider hierarchyStreamProvider, IDocumentationDeclarationProvider parentDocumentation)
            : base(new TocDocumentationLoader<HierarchyStreamProvider>(hierarchyStreamProvider))
        {
            this.parentDocumentationDeclarationProvider = parentDocumentation;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HierarchyDeclarationProvider"/> class.
        /// </summary>
        /// <param name="hierarchyStreamProvider">The hierarchy stream provider.</param>
        public HierarchyDeclarationProvider(HierarchyStreamProvider hierarchyStreamProvider)
            : this(hierarchyStreamProvider, null)
        {
        }

        protected override void OnDocumentationLoaded()
        {
            // Merge the prototypes from the parent documentation declaration provider into our documentation
            if (parentDocumentationDeclarationProvider != null)
                this.Documentation.MergePrototypes(parentDocumentationDeclarationProvider.Documentation);
        }
    }
}
